# GNAFU - "Ground, Navy and Air Fuck-Up" Copyright (C) 2008 k0wax <k0waxk0wax@gmail.com>
#
# This file is part of GNAFU.
#
# GNAFU is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GNAFU is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNAFU.  If not, see <http://www.gnu.org/licenses/>.

from __future__ import division, absolute_import
import pyglet

def exec_callback(cb):
    if hasattr(cb, '__getitem__'):
        #for x in cb:
            #if type(x) in (tuple, list):
            #    x[0](*x[1:]) # fixme, add ability to execute callbacks queue
            #else:
            #    x()
        cb[0](*cb[1:])
        return
    if cb is not None:
        ret = cb()
        #print 'ret', ret
        return ret if type(ret) is type(lambda: True) else ret() if ret != None else False # FIXME!!!

def do_once(cb, delay, *args, **kw):
    def f(dt):
        cb(*args, **kw)
    pyglet.clock.schedule_once(f, delay, *args, **kw)
